/fsize  14 def
/outlinecolor {0.2 setgray} bind def
/paircolor    {0.2 setgray} bind def
/seqcolor     {0   setgray} bind def
/cshow  { dup stringwidth pop -2 div fsize -3 div rmoveto show} bind def
/min { 2 copy gt { exch } if pop } bind def
/max { 2 copy lt { exch } if pop } bind def
/arccoords { % i j arccoords
  % puts optimal x1 y1 x2 y2 coordinates used in bezier curves from i to j
  % onto the stack
  dup 3 -1 roll dup 4 -1 roll lt dup dup 5 2 roll {exch} if
  dup 3 -1 roll dup 3 -1 roll exch sub 1 sub dup
  4 -2 roll 5 -1 roll {exch} if 4 2 roll
  sequence length dup 2 div exch 3 1 roll lt 
  {exch 5 -1 roll pop 4 -2 roll exch 4 2 roll}
  { 4 2 roll 5 -1 roll dup 6 1 roll {exch} if
    4 -2 roll exch pop dup 3 -1 roll dup 4 1 roll
    exch add 4 -1 roll dup 5 1 roll sub 1 sub
    5 -1 roll not {4 -2 roll exch 4 2 roll} if
  }ifelse
   % compute the scalingfactor and prepare (1-sf) and sf*r
  2 mul exch cpr 3 1 roll div dup
  3 -1 roll mul exch 1 exch sub exch
   % compute the coordinates
  3 -1 roll 1 sub coor exch get aload pop % get coord for i
  4 -1 roll dup 5 1 roll mul 3 -1 roll dup 4 1 roll add exch % calculate y1
  4 -1 roll dup 5 1 roll mul 3 -1 roll dup 4 1 roll add exch % calculate x1
  5 -1 roll 1 sub coor exch get aload pop % get coord for j
  % duplicate j coord
  dup 3 -1 roll dup 4 1 roll exch 8 2 roll
  6 -1 roll dup 7 1 roll mul 5 -1 roll dup 6 1 roll add exch % calculate y2
  6 -1 roll mul 5 -1 roll add exch % calculate x2
  6 -2 roll % reorder
} bind def
/drawoutline {
  gsave outlinecolor newpath
  coor 0 get aload pop 0.8 0 360 arc % draw 5' circle of 1st sequence
  currentdict /cutpoint known        % check if cutpoint is defined
  {coor 0 cutpoint getinterval
   {aload pop lineto} forall         % draw outline of 1st sequence
   coor cutpoint 1 add get aload pop
   2 copy moveto 0.8 0 360 arc       % draw 5' circle of 2nd sequence
   coor cutpoint 1 add coor length cutpoint 1 add sub getinterval
   {aload pop lineto} forall        % draw outline of 2nd sequence
     } {
        /i 0 def
        coor {
            /p coor i get def
            /a arcs i get def
            /l a length def
            l 0 eq {
                %% standard point... draw simple line
                p 0 2 getinterval aload pop lineto
            } {
                %% point in loop... draw arc around loop center
                /clockwise a 5 get def
                clockwise 0.0000000 gt {
                    a 0 5 getinterval aload pop arcn
                } {
                    a 0 5 getinterval aload pop arc
                } ifelse
            } ifelse
            /i i 1 add def
        } forall
    }
  ifelse
  stroke grestore
} bind def
/drawpairs {
  paircolor
  0.7 setlinewidth
  [9 3.01] 9 setdash
  newpath
  pairs {aload pop
      currentdict (cpr) known
      { exch dup
        coor  exch 1 sub get aload pop moveto
        exch arccoords curveto
      }
      { coor exch 1 sub get aload pop moveto
        coor exch 1 sub get aload pop lineto
      }ifelse
  } forall
  stroke
} bind def
% draw bases
/drawbases {
  [] 0 setdash
  seqcolor
  0
  coor {
    aload pop moveto
    dup sequence exch 1 getinterval cshow
    1 add
  } forall
  pop
} bind def
/init {
  /Helvetica findfont fsize scalefont setfont
  1 setlinejoin
  1 setlinecap
  0.8 setlinewidth
  % find the coordinate range
  /xmax -1000 def /xmin 10000 def
  /ymax -1000 def /ymin 10000 def
  coor {
      aload pop
      dup ymin lt {dup /ymin exch def} if
      dup ymax gt {/ymax exch def} {pop} ifelse
      dup xmin lt {dup /xmin exch def} if
      dup xmax gt {/xmax exch def} {pop} ifelse
  } forall
  /size {xmax xmin sub ymax ymin sub max} bind def
  /width {xmax xmin sub} bind def
  /height {ymax ymin sub} bind def
  10 10 translate
  680 size 10 add div dup scale
  size width sub width xmin sub xmax sub add 2 div 5 add
  size height sub height ymin sub ymax sub add 2 div 5 add
  translate
} bind def
